﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//a a a a a a a dg f af
namespace WPAChess
{
    public static class SquareColor
    {
        /* define square type */
        public class SquareType
        {
            private Brush eventSquare;
            private Brush oddSquare;
            public SquareType(Brush eventSquare, Brush oddSquare)
            {
                this.eventSquare = eventSquare;
                this.oddSquare = oddSquare;
            }

            public Brush EvenSqure
            {
                get
                {
                    return this.eventSquare;
                }
            }

            public Brush OddSquare
            {
                get
                {
                    return this.oddSquare;
                }
            }
        }
         

        public static SquareType Standard = new SquareType(new SolidColorBrush(Color.FromArgb(255, 193, 124, 66)), new SolidColorBrush(Color.FromArgb(255, 231, 208, 167)));
        public static SquareType DColor1 = new SquareType(new SolidColorBrush(Color.FromArgb(244, 244, 244, 150)), new SolidColorBrush(Color.FromArgb(51, 51, 51, 80)));
        public static SquareType DColor2 = new SquareType(new SolidColorBrush(Color.FromArgb(223, 224, 228, 133)), new SolidColorBrush(Color.FromArgb(125, 182, 255, 250)));
        public static SquareType DColor3 = new SquareType(new SolidColorBrush(Color.FromArgb(224, 206, 158, 50)), new SolidColorBrush(Color.FromArgb(122, 39, 40, 150)));
         
    }

    public class Square
    {
        private byte row;
        private byte col;
        private ChessBoard parent;
        private Grid gridParent;
        private Rectangle rect;

        private bool highLight;

        public Square(ChessBoard parent, byte row, byte col)
        {
            this.rect = new Rectangle();
            rect.Fill = ((col + row) % 2 == 0) ? SquareColor.Standard.EvenSqure : SquareColor.Standard.OddSquare;//new SolidColorBrush(Color.FromArgb(255, 193, 124, 66)) : new SolidColorBrush(Color.FromArgb(255, 231, 208, 167));
            Grid.SetRow(this.rect, row);
            Grid.SetColumn(this.rect, col); 
            rect.StrokeThickness = 2;
            rect.Stroke = new SolidColorBrush(Colors.Black);

            //this.rect.MouseLeftButtonDown += OnMouseLeftButtonDown;

            this.parent = parent;
            this.parent.LayoutRoot.Children.Add(this.rect);
            this.row = row;
            this.col = col;
        }

        /* Ap dung cho nhung grid khac */
        public Square(Grid gridParent, byte row, byte col)
        {
            this.rect = new Rectangle();
            rect.Fill = ((col + row) % 2 == 0) ? SquareColor.Standard.EvenSqure : SquareColor.Standard.OddSquare;//new SolidColorBrush(Color.FromArgb(255, 193, 124, 66)) : new SolidColorBrush(Color.FromArgb(255, 231, 208, 167));
            Grid.SetRow(this.rect, row);
            Grid.SetColumn(this.rect, col);
            rect.StrokeThickness = 2;
            rect.Stroke = new SolidColorBrush(Colors.Black);

            this.gridParent = gridParent;
            this.gridParent.Children.Add(this.rect);
            this.row = row;
            this.col = col;
        }


        public bool HighLight
        {
            get
            {
                return this.highLight;
            }

            set
            {
                this.highLight = value;
                this.UpdateHighLight();
            }
        }

        private void UpdateHighLight()
        {
            if (this.highLight)
            {
                this.rect.StrokeThickness = 10;
                this.rect.Stroke = new SolidColorBrush(Colors.White);
            }
            else
            {
                this.rect.StrokeThickness = 2;
                this.rect.Stroke = new SolidColorBrush(Colors.Black);
            }
        }

        /// <summary>
        /// event: khi click o vuong
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        //{
        //    this.parent.OnSquareClicked(this.row, this.col);
        //}


        public Rectangle GetRect
        {
            get
            {
                return rect;
            }
        }
    }
}
